<?php 
include('common_include.php');
include('validateSession.php');

$orderID = $_GET['orderID'];
$dao = new SQLitePersistence();
$orderHeader = $dao->getOrderHeaderByID($orderID);
$orderDetailsArr = $dao->getOrderDetailsByID($orderID);

?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<script language="javascript" src="scripts/common.js"></script>
<title>
	Settlement Details - Order ID: <?php echo $orderID ?>
</title>
<script>
function updateOrder() {
	document.forms[0].submit();
}

function populateValues() {
	var populateStatus = '<?php echo $orderHeader->getStatus()?>';
	var statusSelect = document.getElementById('statusSelect');
	var i=0;
	if (statusSelect) {
		for (i=0; i < statusSelect.options.length; i++) {
			if (statusSelect.options[i].value == populateStatus) {
				statusSelect.options[i].selected = true;
				break;
			}
		}
	}
}
</script>
</head>

<body onload="populateValues();">
<form action="UpdateOrdersController.php" method="post">
<table>
	<tr>
		<td class="errorLabel" colspan="2">
			<?php echo $_GET['error']; ?>
		</td>
	</tr>
	<tr>
		<td class="labelClass" colspan="2">
			Orders Settlement Information:
		</td>
	</tr>
	<tr>
		<td width="20%">
			Order ID:
		</td>
		<td width="80%">
			<input type="hidden" name="orderID" value="<?php echo $orderID?>"/>
			<?php echo $orderHeader->getOrderId()?>
		</td>
	</tr>
	<tr>
		<td width="20%">
			Customer Name:
		</td>
		<td width="80%">
			<?php echo $orderHeader->getCustName()?>
		</td>
	</tr>
	<tr>
		<td width="20%">
			Customer Contact:
		</td>
		<td width="80%">
			<?php echo $orderHeader->getCustContact()?>
		</td>
	</tr>
	<tr>
		<td width="20%">
			Customer Email:
		</td>
		<td width="80%">
			<?php echo $orderHeader->getCustEmail()?>
		</td>
	</tr>
	<tr>
		<td width="20%">
			Delivery Mode:
		</td>
		<td width="80%">
			<?php echo $orderHeader->getDeliveryMode()?>
		</td>
	</tr>
		<tr>
		<td width="20%">
			Payment Mode:
		</td>
		<td width="80%">
			<?php echo $orderHeader->getPaymentMode()?>
		</td>
	</tr>
	<tr>
		<td width="20%">
			Order Date:
		</td>
		<td width="80%">
			<?php echo $orderHeader->getOrderDt()?>
		</td>
	</tr>
	<tr>
		<td width="20%">
			Remarks:
		</td>
		<td width="80%">
			<?php echo $orderHeader->getRemark()?>
		</td>
	</tr>
	<tr>
		<td width="20%">
			Status:
		</td>
		<td width="80%">
			<select id="statusSelect" name="updatedStatus">
				<option value="NEW">NEW</option>
				<option value="PAID">PAID</option>
			</select>
		</td>
	</tr>	
	<tr>
		<td width="20%">
			Update Date:
		</td>
		<td width="80%">
			<?php echo $orderHeader->getUpdatedDt()?>
		</td>
	</tr>
	<tr>
		<td class="labelClass" colspan="2">
			&nbsp;
		</td>
	</tr>
	<tr>
		<td class="labelClass" colspan="2">
			Order Details Listing:
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<table class="listingTable">
				<tr class="yellow">
					<td class="adjacent">
						Product Code
					</td>
					<td class="adjacent">
						Unit Price
					</td>
					<td class="adjacent">
						Quantity
					</td>	
					<td class="adjacent">
						Size Selected
					</td>
					<td class="adjacent">
						Color Selected
					</td>														
				</tr>
				<?php for ($i=0; $i < sizeof($orderDetailsArr); $i++) {
					$aOrderDetail = $orderDetailsArr[$i];
				?>
				<tr>
					<td>
						<?php echo $aOrderDetail->getProductCode()?>
					</td>
					<td>
						<?php echo $aOrderDetail->getUnitPrice()?>
					</td>
					<td>
						<?php echo $aOrderDetail->getQuantity()?>
					</td>	
					<td>
						<?php echo $aOrderDetail->getSizeSelected()?>
					</td>
					<td>
						<?php echo $aOrderDetail->getColorSelected()?>
					</td>														
				</tr>				
				<?php } 
				unset($orderDetailsArr);?>	
			</table>
		</td>
	</tr>
	<tr>
		<td colspan="2">
			&nbsp;
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<input type="button" value="Update" onclick="updateOrder();"/>
		</td>
	</tr>
</table>
</form>
</body>
</html>
